class Person implements Comparable<Person>{

    public int age;

    public Person(int age) {
        this.age = age;
    }

    @Override
     // compareTo方法里面指定你想要设定的比较规则，指定以什么方式来进行比较
    public int compareTo(Person o) {
        return this.age-o.age;
    }

    @Override
    public String toString() {
        return "Person{" +
                "age=" + age +
                '}';
    }
}
class TestDemo2<E extends Number> {

}
class Alg<T extends Comparable<T>> {
    public T findMax (T[] array) {
        T max = array[0];
        for (int i = 1; i < array.length; i++) {
            //if(max < array[i]) {
            if(max.compareTo(array[i]) < 0 ) {
                max = array[i];
            }
        }
        return max;
    }
}
class Alg2{
    //泛型静态方法
    public static<T extends Comparable<T>> T findMax (T[] array) {
        T max = array[0];
        for (int i = 1; i < array.length; i++) {
            //if(max < array[i]) {
            if(max.compareTo(array[i]) < 0 ) {
                max = array[i];
            }
        }
        return max;
    }
}
class Alg3 {
    //泛型方法
    public <T extends Comparable<T>> T findMax (T[] array) {
        T max = array[0];
        for (int i = 1; i < array.length; i++) {
            //if(max < array[i]) {
            if(max.compareTo(array[i]) < 0 ) {
                max = array[i];
            }
        }
        return max;
    }
}
public class Test2 {
    public static void main(String[] args) {
        Alg3 alg3 = new Alg3();
        Integer[] array = {1,2,3,4};

        Integer ret = alg3.<Integer>findMax(array);
        System.out.println(ret);

    }
    public static void main5(String[] args) {
        Integer[] array = {1,2,3,4};
        Integer ret = Alg2.<Integer>findMax(array);
        System.out.println(ret);
    }
    public static void main4(String[] args) {
        Alg<Integer> alg = new Alg<>();
        Integer[] array = {1,2,3,4};
        Integer ret = alg.findMax(array);
        System.out.println(ret);
    }
    public static void main2(String[] args) {
        TestDemo2<Integer> testDemo2 = new TestDemo2<>();
        TestDemo2<Number> testDemo21 = new TestDemo2<>();
        TestDemo2<Float> testDemo22 = new TestDemo2<>();
        TestDemo2<Double> testDemo23 = new TestDemo2<>();
//  TestDemo2<String> testDemo232 = new TestDemo2<>(); error 因为String不是Number的子类

    }
    public static void main3(String[] args) {
        Alg<Person> alg = new Alg<>();
        Person[] people = {new Person(10),new Person(15)};
        Person person = alg.findMax(people);
        System.out.println(person);
    }

    public static void main1(String[] args) {
        int[] array = {1,2,3,4};
        System.out.println(array[0] > array[1]);
    }
}